package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.xcity.game.chat.ChatChannel;
import com.xcity.game.chat.ChatMessage;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class ChatRecordsResponse extends Response {
	
	public ChatChannel channel;
	public List<ChatRecord> records;
	
	public static class ChatRecord {
		public long time;
		@Deprecated
		public String scope;
		public String content;
		public long fromRoleId;
		public String fromRoleName;
		public String fromRoleImg;
		public long toRoleId;
		public String toRoleName;
		public String toRoleImg;
	}
	
	public ChatRecordsResponse(int serial, ChatChannel channel, Collection<ChatMessage> messages, int offset, int count) {
		super(serial);
		this.channel = channel;
		this.records = new ArrayList<ChatRecord>();
		int off = 0;
		int c = 0;
		for (ChatMessage msg : messages) {
			if (off++ < offset) {
				continue;
			}
			ChatRecord cr = new ChatRecord();
			cr.time = msg.getTime();
			cr.scope = msg.getChannel().name();
			cr.content = msg.getContent();
			cr.fromRoleId = msg.getSrcId();
			cr.fromRoleName = msg.getSrcName();
			cr.fromRoleImg = msg.getSrcIcon();
			cr.toRoleId = msg.getDestId();
			cr.toRoleName = msg.getDestName();
			cr.toRoleImg = msg.getDestIcon();
			this.records.add(cr);
			if (++c >= count) {
				break;
			}
		}
	}

	
}
